package personal.mhc.pardus.service;
import personal.mhc.pardus.model.commodities.VIP;
import personal.mhc.pardus.model.commodities.CommodityImpl;
import personal.mhc.pardus.model.PriceGuide;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import personal.mhc.pardus.service.exception.CommodityException;
/**
* JUnit Test class for PriceGuideService.
*
* @author Mark Camp
*/
public class PriceGuideServiceTest {
/** PriceGuideService that will be used. */
PriceGuideService pgs;
/**
* Default Constructor.
*/
public PriceGuideServiceTest() {
}
/**
* Setup before each test.
*/
@Before
public void setUp() {
// Establish PriceGuideService.
pgs = new PriceGuideService();
}
/**
* Test newPriceGuide() creates a new PriceGuide.
*/
@Test
public void testNewPriceGuide(){
// Call newPriceGuide() to create new PriceGuide.
PriceGuide pg = pgs.newPriceGuide();
// Create generic CommodityImpl.
CommodityImpl comm;
// Loop through all of the commodities.
for(int i =1; i<=44; i++) {
switch (i) {
case 1: comm = pg.getFood();break;
case 2: comm = pg.getEnergy();break;
case 3: comm = pg.getWater();break;
case 4: comm = pg.getAnimalEmbryos();break;
case 5: comm = pg.getOre();break;
case 6: comm = pg.getMetal();break;
case 7: comm = pg.getElectronics();break;
case 8: comm = pg.getRobots();break;
case 9: comm = pg.getHeavyPlastics();break;
case 10: comm = pg.getHandWeapons();break;
case 11: comm = pg.getBattleweaponsParts();break;
case 12: comm = pg.getDroidModules();break;
case 13: comm = pg.getRadioactiveCells();break;
case 14: comm = pg.getMedicines();break;
case 15: comm = pg.getNebulaGas();break;
case 16: comm = pg.getChemicalSupplies();break;
case 17: comm = pg.getGemStones();break;
case 18: comm = pg.getOpticalComponents();break;
case 19: comm = pg.getLiquor();break;
case 20: comm = pg.getHydrogenFuel();break;
case 21: comm = pg.getExoticMatter();break;
case 22: comm = pg.getBioWaste();break;
case 23: comm = pg.getSlaves();break;
case 24: comm = pg.getDrugs();break;
case 25: comm = pg.getNutrientClods();break;
case 26: comm = pg.getCyberneticX993Parts();break;
case 27: comm = pg.getExoticCrystal();break;
case 28: comm = pg.getBlueSapphireJewels();break;
case 29: comm = pg.getRubyJewels();break;
case 30: comm = pg.getGoldenBerylJewels();break;
case 31: comm = pg.getNeuralTissue();break;
case 32: comm = pg.getStimChip();break;
case 33: comm = pg.getLeechBaby();break;
case 34: comm = pg.getMilitaryExplosives();break;
case 35: comm = pg.getHumanIntestines();break;
case 36: comm = pg.getSkaariLimbs(); break;
case 37: comm = pg.getKeldonBrains();break;
case 38: comm = pg.getRashkirBones(); break;
case 39: comm = pg.getPackages(); break;
case 40: comm = pg.getFactionPackage(); break;
case 41: comm = pg.getExplosives();break;
case 42: comm = pg.getVIP(); break;
case 43: comm = pg.getNeuralStimulator();break;
case 44: comm = pg.getX993RepairDrone();break;
default: comm = pg.getFood();break;
}
// Check that the commodity is established.
assertTrue(comm.getAmount() == 0);
assertTrue(comm.getMax() == 0);
assertTrue(comm.getDesiredBuy() == 0);
assertTrue(comm.getDesiredSell() == 0);
}
}
/**
* Test updatePriceGuide(...) works with a priceGuide.
*/
@Test
public void testUpdatePriceGuide(){
// Create CommodityImpl to update.
CommodityImpl commodity = new VIP();
// Set commodity's amount.
commodity.setAmount(10);
// Create a priceGuide.
PriceGuide priceGuide = pgs.newPriceGuide();
// Call updatePriceGuide with a PriceGuide.
PriceGuide pg = null;
try {
pg = pgs.updatePriceGuide(priceGuide, commodity);
} catch (CommodityException ex) {
fail();
}
// Did it update the commodity?
assertTrue(pg.getVIP().getAmount() == commodity.getAmount());
// Did it leave other commodities alone?
assertTrue(pg.getFood().getAmount() == 0);
}
/**
* Test updatePriceGuide(...) works even though there is no priceGuide provided.
*/
@Test
public void testUpdatePriceGuideNoPriceGuideProvided(){
// Create CommodityImpl to update.
CommodityImpl commodity = new VIP();
// Set commodity's amount.
commodity.setAmount(10);
// Call updatePriceGuide without having a PriceGuide.
PriceGuide pg = null;
try {
pg = pgs.updatePriceGuide(null, commodity);
} catch (CommodityException ex) {
fail();
}
// Did it update the commodity?
assertTrue(pg.getVIP().getAmount() == commodity.getAmount());
// Did it leave other commodities alone?
assertTrue(pg.getFood().getAmount() == 0);
}
/**
* Test updatePriceGuide(...) throws exception when there is no commodity provided.
*/
@Test
public void testUpdatePriceGuideNoCommodityProvided(){
try {
// Call updatePriceGuide without having a Commodity.
pgs.updatePriceGuide(pgs.newPriceGuide(), null);
// Exception should have been thrown.
fail();
} catch (CommodityException ex) {
// Exception was thrown.
assertTrue(true);
}
}
}